<?php

namespace App\Http\Controllers\Backend;

use App\Http\Resources\Backend\FoodResource;
use App\Models\Food;
use Illuminate\Http\Request;

/**
 * Class FoodController
 * @package App\Http\Controllers\Backend
 * 菜品
 */
class FoodController extends BackendController
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
     */
    public function index(Request $request)
    {
        $foods = Food::orderBy('created_at', 'desc')
            ->with('type')->with('school')
            ->schoolIs($request->school_id)
            ->foodTypeIs($request->food_type)
            ->supplyTypeIs($request->supply_type)
            ->nameLike($request->name)
            ->paginate($request->size);
        return FoodResource::collection($foods);
    }
}